from django.db.models import Avg
from django.test import TestCase

from .models import History, Score
# Create your tests here.
import jiagu
import os

#jiagu.init() # 可手动初始化，也可以动态初始化

text = '厦门明天会不会下雨'

words = jiagu.seg(text) # 分词
print(words)

pos = jiagu.pos(words) # 词性标注
print(pos)

ner = jiagu.ner(words) # 命名实体识别
print(ner)


text1 = '汉服和服装、维基图谱'

words = jiagu.seg(text1)
print(words)

# jiagu.load_userdict('dict/user.dict') # 加载自定义字典，支持字典路径、字典列表形式。
jiagu.load_userdict(['汉服和服装'])

words = jiagu.seg(text1) # 自定义分词，字典分词模式有效
print(words)

print("*3*hello ni hao ya*".strip("*"));

def count_score():
    scores = History.objects.values('text').annotate(avg_score=Avg('score'))

    # 插入 Score 表
    for score in scores:
        text, avg_score = score['text'], score['avg_score']
        Score.objects.create(text=text, score=avg_score)